[id].vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="admin--page-content">
  3. <div class="admin--form">
  4. <!-- 낚시분야 상세 -->
  5. <table class="admin--form--table">
  6. <colgroup>
  7. <col style="width: 120px;">
  8. <col>
  9. </colgroup>
  10. <tbody>
  11. <tr>
  12. <th><div>분야</div></th>
  13. <td>{{ formData.name || "-" }}</td>
  14. </tr>
  15. <tr>
  16. <th><div>가중치</div></th>
  17. <td class="color--yellow">{{ formData.weight || "-" }}</td>
  18. </tr>
  19. <tr>
  20. <th><div>상태</div></th>
  21. <td>
  22. <span :class="['admin--badge', formData.status_YN === 'Y' ? 'admin--badge-active' : 'admin--badge-ended']">
  23. {{ formData.status_YN === "Y" ? "사용중" : "미사용" }}
  24. </span>
  25. </td>
  26. </tr>
  27. <tr>
  28. <th><div>등록일</div></th>
  29. <td>{{ formatDateTime(formData.created_at) }}</td>
  30. </tr>
  31. <tr>
  32. <th><div>최근 수정</div></th>
  33. <td>{{ formatDateTime(formData.updated_at) }}</td>
  34. </tr>
  35. <tr>
  36. <th><div>사용 챌린지</div></th>
  37. <td></td>
  38. </tr>
  39. <tr>
  40. <th><div>사용 퀘스트</div></th>
  41. <td></td>
  42. </tr>
  43. </tbody>
  44. </table>
  45. <!-- 버튼 영역 -->
  46. <div class="admin--form-actions">
  47. <button type="button" class="admin--btn" @click="goToList">
  48. ← 목록으로
  49. </button>
  50. <button type="button" class="admin--btn admin--btn-red-border ml--auto" @click="handleDelete">
  51. 삭제
  52. </button>
  53. <button type="button" class="admin--btn admin--btn-red" @click="goToEdit">
  54. 수정
  55. </button>
  56. </div>
  57. <!-- 알림 모달 -->
  58. <AdminAlertModal
  59. v-if="alertModal.show"
  60. :title="alertModal.title"
  61. :message="alertModal.message"
  62. :type="alertModal.type"
  63. @confirm="handleAlertConfirm"
  64. @cancel="handleAlertCancel"
  65. @close="closeAlertModal"
  66. />
  67. </div>
  68. </div>
  69. </template>
  70. <script setup>
  71. import { ref, onMounted } from "vue";
  72. import { useRoute, useRouter } from "vue-router";
  73. import AdminAlertModal from "~/components/admin/AdminAlertModal.vue";
  74. definePageMeta({
  75. layout: "admin",
  76. middleware: ["auth"],
  77. });
  78. const route = useRoute();
  79. const router = useRouter();
  80. const { get, del } = useApi();
  81. const fieldId = route.params.id;
  82. const formData = ref({
  83. name: "",
  84. weight: "",
  85. status_YN: "Y",
  86. created_at: "",
  87. updated_at: "",
  88. });
  89. // 알림 모달
  90. const alertModal = ref({
  91. show: false,
  92. title: "알림",
  93. message: "",
  94. type: "alert",
  95. onConfirm: null,
  96. });
  97. const showAlert = (message, title = "알림") => {
  98. alertModal.value = { show: true, title, message, type: "alert", onConfirm: null };
  99. };
  100. const showConfirm = (message, onConfirm, title = "확인") => {
  101. alertModal.value = { show: true, title, message, type: "confirm", onConfirm };
  102. };
  103. const closeAlertModal = () => { alertModal.value.show = false; };
  104. const handleAlertConfirm = () => {
  105. if (alertModal.value.onConfirm) alertModal.value.onConfirm();
  106. closeAlertModal();
  107. };
  108. const handleAlertCancel = () => closeAlertModal();
  109. // 상세 조회
  110. const loadDetail = async () => {
  111. const { data, error } = await get(`/field/${fieldId}`);
  112. if (error || !data?.success) {
  113. showAlert(error?.message || data?.message || "조회에 실패했습니다.", "오류");
  114. return;
  115. }
  116. const row = data.data || {};
  117. formData.value = {
  118. name: row.name ?? "",
  119. weight: row.weight ?? "",
  120. status_YN: row.status_YN ?? "Y",
  121. created_at: row.created_at ?? "",
  122. updated_at: row.updated_at ?? "",
  123. };
  124. };
  125. // 삭제
  126. const handleDelete = () => {
  127. showConfirm(
  128. `'${formData.value.name}' 낚시분야를 삭제하시겠습니까?`,
  129. async () => {
  130. const { data, error } = await del(`/field/${fieldId}`);
  131. if (error || !data?.success) {
  132. showAlert(error?.message || data?.message || "삭제에 실패했습니다.", "오류");
  133. } else {
  134. showAlert(data.message || "삭제되었습니다.", "성공");
  135. setTimeout(() => router.push("/site-manager/field/list"), 800);
  136. }
  137. },
  138. "낚시분야 삭제"
  139. );
  140. };
  141. // 이동
  142. const goToList = () => router.push("/site-manager/field/list");
  143. const goToEdit = () => router.push(`/site-manager/field/edit/${fieldId}`);
  144. // 일시 포맷
  145. const formatDateTime = (dateString) => {
  146. if (!dateString) return "-";
  147. const date = new Date(dateString.replace(" ", "T"));
  148. if (isNaN(date.getTime())) return dateString;
  149. return date.toLocaleString("ko-KR", {
  150. year: "numeric",
  151. month: "2-digit",
  152. day: "2-digit",
  153. hour: "2-digit",
  154. minute: "2-digit",
  155. });
  156. };
  157. onMounted(() => {
  158. loadDetail();
  159. });
  160. </script>